<template>
  <div class="news">
    <div class="main">
      <el-table class="table" :data="tableData" style="width: 100%">
        <el-table-column prop="title" label="标题" row-style>
          <template slot-scope="scope">
            <div @click="toDetail(scope.row.id)" class="article" v-if="scope.row.type == 1">{{ scope.row.title }}</div>
            <a class="article" target="_blank" v-if="scope.row.type == 2" :href="scope.row.linkUrl">{{ scope.row.title }}</a>
          </template>
        </el-table-column>
        <el-table-column prop="views" label="浏览量" width="100">
          <template slot-scope="scope">
            <span>{{ scope.row.type == 1 ? scope.row.views : '-' }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="author" label="作者" width="120"></el-table-column>
        <el-table-column prop="publishTime" label="发布时间" width="180"></el-table-column>
      </el-table>
      <el-pagination
          :hide-on-single-page="true"
          @current-change="changePage"
          layout="prev, pager, next"
          :total="total">
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { articles, articleAddViews } from "@/api/Mange/Mange";

export default {
  data() {
    return {
      queryParams: {
        pageNo: 1,
        size: 10,
      },
      total: 0,
      tableData: [],
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      articles(this.queryParams).then((res) => {
        if (res.status) {
          this.tableData = res.data.records;
          this.total = res.data.total
        }
      });
    },
    changePage(pageNo) {
      this.queryParams.pageNo = pageNo;
      this.getList();
    },
    toDetail(id) {
      articleAddViews(id).then(res => {
        this.$router.push({ path: "/News/detail/" + id});
      });
    },
  },
};
</script>
<style lang="less">
.news {
  height: 100vh;
  background-color: #0e092b;
  .btn {
    width: 104px;
    height: 30px;
    background-color: #d14649;
    color: #3e3131;
    text-align: center;
    line-height: 30px;
    display: inline-block;
    font-size: 16px;
    vertical-align: middle;
    margin-left: 10px;
    cursor: pointer;
  }
  .titleH3 {
    color: #fff;
    font-size: 56px;
    font-weight: normal;
    padding: 1px 0 20px 0;
    margin-left: 85px;
    margin-top: 80px;
  }
  .main {
    margin-left: 60px;
    width: 80%;

    padding-left: 30px;
    padding-top: 20px;
    .el-table__body-wrapper {
      background-color: #0e092b;
    }
    .table td,
    th {
      background-color: #0e092b;
      color: #fff;
    }
     .table .el-table tr:hover {
       background-color: #000;
     }
     .el-table--enable-row-hover .el-table__body tr:hover > td.el-table__cell {
       background-color: rgb(13 13 17);
       color: #fff;
     }
    .article {
      text-decoration: none;
      cursor: pointer;
      color: #fff;
      font-weight: bold;
    }
  }
}
</style>

